package com.bjsxt.thread;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

public class JoinDemo {
    public static void main(String[] args) {
        System.out.println("爸爸买烟的故事");
        Thread t = new Thread(new FatherThread());
        t.start();
    }
}

class FatherThread implements Runnable{

    @Override
    public void run() {
        System.out.println("爸爸想抽烟，发现没烟了");
        Thread t = new Thread(new SonThread());
        t.start();
        System.out.println("爸爸等烟");
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("爸爸出门找儿子");
            System.exit(1);
        }
        System.out.println("爸爸拿到烟给零钱儿子");
    }
}

class SonThread implements Runnable{

    @Override
    public void run() {
        System.out.println("儿子买烟");
        System.out.println("用十分钟");
        for (int i=0;i<10;i++){
            System.out.println("第"+i+"分钟");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
        System.out.println("买回来了");
    }
}